package com.longge;

/**
 * @创建人 xinglongge
 * @创建时间 2021/11/22
 * @描述
 */
public class IsValidSudoku {
    public boolean isValidSudoku(char[][] board) {
        int[][] rows = new int[9][9];
        int[][] columns = new int[9][9];
        int[][][] subboxes = new int[3][3][9];

        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[i].length; j++) {
                char c = board[i][j];
                if (c != '.') {
                    int num = c - '0' - 1;
                    rows[i][num]++;
                    columns[j][num]++;
                    subboxes[i / 3][j / 3][num]++;
                    if (rows[i][num] > 1 || columns[j][num] > 1 || subboxes[i / 3][j / 3][num] > 1) return false;
                }
            }
        }
        return true;
    }

}
